package com.example.hasee.plant.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.hasee.plant.R;
import com.example.hasee.plant.config.MSharePreference;
import com.example.hasee.plant.config.MyApplication;

public class WriteNumberActivity extends AppCompatActivity {

    EditText edt_num;
    Button btn_next,btn_datalist;
    String num;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        edt_num= (EditText) findViewById(R.id.edt_num);
        btn_next= (Button) findViewById(R.id.btn_next);
        btn_datalist= (Button) findViewById(R.id.btn_datalist);
        listener();
        MSharePreference.remove(getApplicationContext(),null);
    }

    private void listener(){
        btn_next.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(edt_num.getText().toString()==null||edt_num.getText().toString().equals("")){
                    Toast.makeText(WriteNumberActivity.this, "采集编码不能为空", Toast.LENGTH_SHORT).show();
                }else{
                    num=edt_num.getText().toString();
                    MyApplication.GATHER_NUM=num;
                    Bundle b=new Bundle();
                    b.putString("num",num);
                    Intent intent=new Intent(WriteNumberActivity
                    .this,GatherDataActivity.class);
                    intent.putExtras(b);
                    startActivity(intent);
                }
            }
        });

        btn_datalist.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(WriteNumberActivity.this,DataListActivity.class);
                startActivity(intent);
            }
        });
    }

}
